﻿using System;
using System.Web.Mvc;
using MyIocContainer;
using Sklep.Domain.Abstract;
using Sklep.Domain.Concrete;
using Sklep.WebUI.Infrastructure.Abstract;
using Sklep.WebUI.Infrastructure.Concrete;

namespace Sklep.WebUI.Infrastructure
{
    public class MyIocControllerFactory : DefaultControllerFactory
    {
        private readonly IContainer _container;
        public MyIocControllerFactory(IContainer container)
        {
            _container = container;
            AddBindings();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null :
            (IController)_container.Resolve(controllerType);
        }

        private void AddBindings()
        {
            _container.Register<IProductRepository,EFProductRepository>();
            _container.Register<IOrderProcessor,EmailOrderProcessor>();
            _container.Register<IAuthProvider,FormsAuthProvider>();

        }
    }
}